package com.dongdong.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdong.constant.ResultConstant;
import com.dongdong.domain.Result;
import com.dongdong.em.ResultEnum;
import com.dongdong.pojo.TbBrand;
import com.dongdong.service.TbBrandService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("tbBrandController")
public class TbBrandController {
  @Reference
  private TbBrandService tbBrandService;
    @RequestMapping("getBrand")
    public String getBrand(){
        return "/admin/brand";
    }
    @RequestMapping("getShow")
    @ResponseBody
    public Result getShow(){
        List<TbBrand> list = tbBrandService.getShow();
//        return new Result(ResultConstant.SUCCESS_CODE,ResultConstant.SUCCESS_MESSAGE,list);
        return Result.buildResult(ResultEnum.SUCCESS).setData(list);
    }

    @RequestMapping("toAdd")
    @ResponseBody
    public Result toAdd(TbBrand tbBrand){
        Boolean b =  tbBrandService.toAdd(tbBrand);
        return Result.buildResult(ResultEnum.SUCCESS).setData(b);
    }
    @RequestMapping("toUpdate")
    @ResponseBody
    public  Result toUpdate(Long id){
        TbBrand tbBrand = tbBrandService.toUpdate(id);
        return  Result.buildResult(ResultEnum.SUCCESS).setData(tbBrand);
    }
    @RequestMapping("updateInfo")
    @ResponseBody
    public Result updateInfo(TbBrand tbBrand){
      tbBrandService.updateInfo(tbBrand);
        return  Result.buildResult(ResultEnum.SUCCESS).setData(tbBrand);
    }
    @RequestMapping("deleteAll")
    @ResponseBody
    public Result deleteAll(@RequestParam("ids[]")Long[] ids){
        Boolean b =  tbBrandService.deleteAll(ids);
        return  Result.buildResult(ResultEnum.SUCCESS).setData(b);
    }
}
